package part_1;

import java.util.ArrayList;
import java.util.Random;

//random algorithm for monley problem
public class Random_monkey_alg 
{
	int TEXT_SIZE=200;
	int MAX_ITERATIONS=100000;
	public void run_alg(String hamlet_file, ArrayList<Character> alphabet) 
	{
		Random r = new Random();
		int index;
		String text="";
		int count=0;
		
		//running for MAX_ITERATIONS
		while(count<MAX_ITERATIONS && text.intern()!=hamlet_file.intern())
		{
			text="";
			//altering the text randomly
			for(int i=0;i<TEXT_SIZE;i++)
			{
				index=r.nextInt(alphabet.size());
				text+=alphabet.get(index);
			}
			
			count++;
		}
		
		//converged in the end
		if(text.intern()==hamlet_file.intern())
		{
			System.out.println("converged after: " + count + " iterations");
		}
		else
		{
			System.out.println("didn't converge");
		}
	}
}
